Copyright 2019 Google LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This will generate the Tabulamuris data used.
The TabulaMurisData was of huge help here !
In [1]:
library(Seurat)
suppressPackageStartupMessages({
library(ExperimentHub)
library(SingleCellExperiment)
library(TabulaMurisData)
})
#> snapshotDate(): 2018-10-31
library(scater)
library(scran)
library(ggplot2)
In [2]:
run_qc <- function(sce) {
isSpike(sce, "ERCC") <- grepl("^ERCC", rownames(sce))
sce <- calculateQCMetrics(sce)
# Identify outliers, but without using the mouse as a batch
libsize.drop <- isOutlier(sce$total_counts, nmads=3, type="lower", log=TRUE)
feature.drop <- isOutlier(sce$total_features_by_counts, nmads=3, type="lower", log=TRUE)
spike.drop <- isOutlier(sce$pct_counts_ERCC, nmads=3, type="higher")
keep <- !(libsize.drop | feature.drop | spike.drop)
sce <- sce[,keep]
num.cells <- nexprs(sce, byrow=TRUE)
to.keep <- num.cells > 0
sce <- sce[to.keep,]
sce
}
In [3]:
eh <- ExperimentHub()
#> snapshotDate(): 2018-10-31
query(eh, "TabulaMurisData")
In [4]:
sce <- eh[["EH1618"]]
sce <- sce[, sce$tissue == 'Skin' |
sce$tissue == 'Large_Intestine' |
sce$tissue == 'Spleen' |
sce$tissue == 'Brain_Myeloid']
sce <- run_qc(sce)
In [5]:
sce$label <- sce$tissue
sce$subtissue[is.na(sce$subtissue)] <- 'None'
sce$cell_ontology_class[is.na(sce$cell_ontology_class)] <- 'None'
sce$cell_ontology_id[is.na(sce$cell_ontology_id)] <- 'None'
sce$free_annotation[is.na(sce$free_annotation)] <- 'None'
sce$FACS_selection[is.na(sce$FACS_selection)] <- 'None'
write.csv(as.matrix(counts(sce)), 'tm_tissue_mix.12k.counts.csv')
write.csv(colData(sce), 'tm_tissue_mix.12k.metadata.csv')
write.csv(rowData(sce), 'tm_tissue_mix.12k.featuredata.csv')
saveRDS(sce, paste('cell_mix/tm_tissue_mix.12k', 'rds', sep='.'))
In [6]:
sce
In [46]:
dat <- as.Seurat(sce, counts='counts', data='counts')
dat <- NormalizeData(dat)
dat <- FindVariableFeatures(dat)
all.genes <- rownames(dat)
dat <- ScaleData(dat, features = all.genes)
dat <- RunPCA(dat)
In [47]:
DimPlot(dat, reduction = 'pca', group.by = 'tissue')
In [10]:
DimPlot(subset(dat, subset = tissue == 'Thymus' | tissue == 'Spleen'), reduction = 'pca', group.by = 'cell_ontology_class')
In [16]:
DimPlot(subset(dat, subset = tissue == 'Thymus' | tissue == 'Spleen'), reduction = 'pca', group.by = 'tissue')
In [11]:
DimPlot(subset(dat, subset = tissue == 'Skin' | tissue == 'Tongue'), reduction = 'pca', group.by = 'cell_ontology_class')
In [15]:
DimPlot(subset(dat, subset = tissue == 'Skin' | tissue == 'Tongue'), reduction = 'pca', group.by = 'tissue')
In [48]:
dat <- RunUMAP(dat, dims=1:10)
In [49]:
DimPlot(dat, reduction = 'umap', group.by = 'tissue')
In [20]:
DimPlot(subset(dat, subset = tissue == 'Skin' | tissue == 'Tongue'), reduction = 'umap', group.by = 'cell_ontology_class')
In [24]:
DimPlot(subset(dat, subset = tissue == 'Skin' | tissue == 'Tongue'), reduction = 'umap', group.by = 'tissue')
In [25]:
DimPlot(subset(dat, subset = tissue == 'Spleen' | tissue == 'Thymus'), reduction = 'umap', group.by = 'cell_ontology_class')
In [44]:
In [50]:
In [5]:
sce$tissue <- as.factor(sce$tissue)
summary(sce$tissue)